﻿using System;
using System.Collections.Generic;
using System.Linq;
using eCRAM.Model;
using eCRAM.Dao;

namespace eCRAM.Bll
{
    public class ActivityManager 
    {
        public static Activity GetFirtsActivity()
        {
            return ActivityRepository.GetTop(0, 1).First();
        }

        public static IEnumerable<String> GetAllActivityName()
        {
            return ActivityRepository.GetAllActivityName();
        }

        public static IEnumerable<Activity> GetAll()
        {
            return ActivityRepository.GetAll();
        }

        public static Activity GetActivityById(Guid id)
        {
            return ActivityRepository.GetById(id);
        }

        public static void Create(Activity activity)
        {
            ActivityRepository.Create(activity);
        }

        public static void Update(Activity activity)
        {
            ActivityRepository.Update(activity);
        }

        public static IEnumerable<ActivityType> GetAllActivityTypes()
        {
            return ActivityRepository.GetAllActivityTypes();
        }

        public static IEnumerable<Activity> GetAvailableUserActivityList(Guid idUser)
        {
            return ActivityRepository.GetAvailableUserActivityList(idUser);
        }

        public static IEnumerable<Activity> GetAvailableUserActivityListAndHolidays(Guid idUser)
        {
            return ActivityRepository.GetAvailableUserActivityListAndHolidays(idUser);
        }

        public static IEnumerable<Activity> GetUserActivityList(Guid idUser)
        {
            return ActivityRepository.GetUserActivityList(idUser);
        }

        public static IEnumerable<Activity> GetRestrictedActivityList(Guid idUser)
        {
            return ActivityRepository.GetRestrictedActivityList(idUser);
        }

        /// <summary>
        /// Obtient un tableau des congés triés tel qu'ils doivent apparaitre dans les exports excel
        /// </summary>
        /// <returns></returns>
        public static Activity[] GetOrderedHolidaysForExcel()
        {
            var listHolidays = ActivityRepository.GetAll()
           .Where(a => a.ActivityType.IsHoliday);

            // l'ordre de tri des activités est important pour rester en cohérence avec les macros VBA
            // Toutefois peut mieux faire...
            var tabHolidays = new Activity[6];
            tabHolidays[0] = null;
            tabHolidays[1] = listHolidays.FirstOrDefault(a => a.Name == "Congés payés");
            tabHolidays[2] = listHolidays.FirstOrDefault(a => a.Name == "JTL salarié");
            tabHolidays[3] = listHolidays.FirstOrDefault(a => a.Name == "JTL Aptea");
            tabHolidays[4] = listHolidays.FirstOrDefault(a => a.Name == "Arrêt maladie");
            tabHolidays[5] = listHolidays.FirstOrDefault(a => a.Name == "Congés autres");
            return tabHolidays;
        }
    }
}
